package cz.muni.fi.pa165.library.backend;

import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Filip Ligac
 */
public interface BorrowDAO {

    /**
     * Set entity manager. Useful for mocking tests.
     *
     * @param entityManager
     */
    void setEntityManager(EntityManager entityManager);

    /**
     * Creates a new borrow and stores it into database.
     *
     * @param borrow borrow entity to be created
     * @return created borrow
     * @throws IllegalArgumentException if borrow is null or borrow's attributes
     * are not correct or sufficient
     */
    public Borrow createBorrow(Borrow borrow);

    /**
     * Returns a list of all borrows in the database.
     *
     * @return list of all borrows in the database.
     */
    public List<Borrow> findAllBorrows();

    /**
     * Returns borrow for a given borrowID.
     *
     * @param borrowID ID of a borrow
     * @return borrow of a given borrowID
     * @throws IllegalArgumentException if id is null or not positive
     */
    public Borrow findBorrowById(Long borrowID);

    /**
     * Returns borrows for a given readerID.
     *
     * @param reader reader who made the borrows
     * @return borrows of a given readerID
     * @throws IllegalArgumentException if id is null or not positive
     */
    public List<Borrow> findBorrowsByReader(Reader reader);

    /**
     * Returns borrow with a given bookID.
     *
     * @param title title
     * @return borrow for a given title
     * @throws IllegalArgumentException if id is null or not positive
     */
    public Borrow findBorrowByTitle(Book title);

    /**
     * Updates expiration date for a borrow.
     *
     * @param borrow Borrow to be updated
     * @param newExpirationDate new expiration date for a borrow
     * @return borrow with updated expiration date
     * @throws IllegalArgumentException if parameter(s) are incorrect
     */
    public void updateExpirationDate(Borrow borrow, Date newExpirationDate);

    /**
     * Returns a few books from a borrow.
     *
     * @param borrow borrow
     * @param titles list of all books to be returned
     * @return borrow with returned books
     * @throws IllegalArgumentException if parameter(s) are incorrect
     */
    public Borrow returnBooks(Borrow borrow, List<Book> titles);

    /**
     * Adds books to an existing borrow.
     *
     * @param borrow borrow
     * @param titles list of all books to be returned
     * @return borrow with added books
     * @throws IllegalArgumentException if parameter(s) are incorrect
     */
    public void borrowBooks(Borrow borrow, List<Book> titles);

    /**
     * Deletes borrow from database.
     *
     * @param borrow borrow to be deleted
     * @return true if deleted successfully, false otherwise
     * @throws IllegalArgumentException if parameter is null
     */
    public boolean deleteBorrow(Borrow borrow);
}
